
/*
 * @Descripttion: 连接数据库mysql
 * @version: 
 * @Author: sueRimn
 * @Date: 2022-09-28 14:36:47
 * @LastEditors: sueRimn
 * @LastEditTime: 2023-02-23 16:48:33
 */
let mysql = require("mysql");

let db = mysql.createPool({
  host: "127.0.0.1",
  user: "root",
  password: "root",
  database: "vue_managerment_system"
})
let query = async function (sqlStr) {
  return await new Promise((resolve, reject) => {
    db.getConnection(function (err, conn) {
      if (err) {
        return reject({
          status: 0,
          message: err.message
        });
      } else {
        conn.query(sqlStr, (err, rows) => {
          conn.release();
          if (err) {
            return reject({
              status: 0,
              message: "failed",
              data: err.message
            });
          } else {
            return resolve({
              status: 1,
              message: "ok",
              data: rows
            })
          }
        })
      }
    })
  })
}
module.exports = { query };